package com.qkl.xiatang.app.dto.feed;

import com.qkl.xiatang.app.dto.message.FeedMsgDTO;
import com.qkl.xiatang.app.entity.feed.FeedEntity;
import com.qkl.xiatang.app.utils.MsgUtils;
import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

@Data
public class FeedVO {

    private List<FeedEntity> entityList;

    private List<FeedMsgDTO> feedMsgList;

    private List<String> imageList;

    private List<String> nameList;


    public void  fetchImageNameList(){
        imageList = new ArrayList<>();
        nameList = new ArrayList<>();
        if(ObjectUtils.isNotEmpty(feedMsgList)){
            for (FeedMsgDTO msgDTO : feedMsgList){
                imageList.add(msgDTO.getImg());
                nameList.add(msgDTO.getFeedName());
            }
        }else if(ObjectUtils.isNotEmpty(entityList)){
            for (FeedEntity entity : entityList){
                imageList.add(entity.getImage());
                nameList.add(entity.getName());
            }
        }
    }

    public String toMessageNameList(){
        if(ObjectUtils.isEmpty(nameList)){
            fetchImageNameList();
        }
        return toMessage(nameList);
    }

    private String toMessage(List<String> strings){
        return MsgUtils.formatMessage(strings);
    }


}
